$(function () {
    var fn = ABUS.Fn;
    var listData = [];

    document.addEventListener('touchmove', function (e) {
        e.preventDefault();
        isDrag = true;
    }, {passive: false});

    $('#sorting').on('touchend', function (e) {
        var $modal = $('.sorting');
        if ($modal.is(":visible")) {
            $modal.hide();
        }
        else {
            $modal.show();
        }
        e.stopPropagation();
    });
    $('body').on('touchend', function () {
        $('.sorting').hide();
    });

    $("#being_process").on("touchend", "li", function () {
        if (isDrag) {
            isDrag = false;
            return true;
        }
        var data = listData[$(this).index()];
        fn.page_goto({
            url : "../banli/zuzhang_banli_pendingPay.html",
            data : data
        })
    });

    $("#sorting_list").on("touchend", "li", function () {
        fn.get({
            url: "/leader/order/historyOrders",
            data: {
                "searchValue": $('#searchInput').val(),
                "orderBy": $(this).data('value'),//1业务类型 2剩余时间 3开始时间
                "orderType": "ASC"
            },
            success: function (data) {
                $("#being_process").renderTemp(data);
                new IScroll('#being_process', {mouseWheel: true});
            }
        });
    });

    $('#searchInput').on('input', _.debounce(function (e) {
        var str = $(this).val();
        init(str)
    },500));

    init('');
    function init(val) {
        fn.get({
            url: "/leader/order/historyOrders",
            data: {
                "searchValue": val,
                "orderBy": "",//1业务类型 2剩余时间 3开始时间
                "orderType": ""
            },
            success: function (data) {
                $("#being_process").renderTemp(data);
                listData = data.data;
                new IScroll('#being_process', {mouseWheel: true});
            }
        });
    }
});